﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Org.BouncyCastle.Asn1.Crmf;
using Org.BouncyCastle.Asn1.Mozilla;
using System.Diagnostics.Contracts;
using ZH.Infrastructure.Dto.Request.Emp;
using ZH.Infrastructure.Dto.Response.Emp;
using ZH.Infrastructure.EFCore.MySql;
using ZH.Service.Instance;
using ZH.Service.Interface;

namespace ZH.Api.Admin.Controllers.Admin
{
    /// <summary>
    /// 管理端·员工
    /// </summary>
    public class EmployeeController : BaseController
    {
        private readonly I_Emp_Service _Emp_Service;

        public EmployeeController(I_Login_Service login_Service, I_Emp_Service Emp_Service) : base(login_Service)
        {
            _Emp_Service = Emp_Service;
        }


        /// <summary>
        /// 获取员工列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limt"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Emp(int? page = 1, int? limt = 10, string? key = "") {

            var result = await _Emp_Service.Get_Emp(
                new Emp_Response_Dto
                {
                    page = page ?? 1,
                    limit = limt ?? 10,
                    key = key ?? ""
                }
                );

            return Ok(result);
        }

        /// <summary>
        /// 添加员工
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Emp(Emp_Request_Dto dto) {

            var result = await _Emp_Service.Add_Emp(dto);
            return Ok(result);
        }


        /// <summary>
        /// 修改员工
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update_Emp(Emp_Request_Dto dto) {

          var result = await _Emp_Service.Update_Emp(dto);
                
          return Ok(result); 
        }
        /// <summary>
        /// 删除员工
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_Emp(string? id) {
            var result = await _Emp_Service.Delete_Emp(id);
            return Ok(result);
            
        
        }
    }
}
